local shifu_vs = fk.CreateSkill {
  name = "th_shifu&",
}

shifu_vs:addEffect("viewas", {
  pattern = "slash,jink",
  mute_card = false,
  interaction = function(self, player)
    local all_names = { "slash", "jink" }
    local names = player:getViewAsCardNames("th_shifu", all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  view_as = function(self, player,cards)
    if not self.interaction.data then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = "th_shifu"
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:doIndicate(player.id, use.tos)
    for _, chen in ipairs(player:getTableMark("th_shifu")) do
      local name = use.card.name
      local card = room:askToResponse(chen, {
        skill_name = "basic",
        pattern = ".|.|.|.|.|basic",
        prompt = "#th_shifu-ask::"..player.id..":"..Fk:translate(name)
      })
      if card then
        card.skipDrop = true
        room:responseCard(card)
        chen:drawCards(1, "th_shifu")
        return
      end
    end
    if player.phase == Player.Play then
      room:addPlayerMark(player, "_th_shifu_failed-phase")
    end
    return shifu_vs.name
  end,
  enabled_at_play = function(self, player)
    return player:getMark("_th_shifu_failed-phase") == 0 and table.find(player:getTableMark("th_shifu"), function(chen)
      return chen and not chen.dead
    end)
  end,
  enabled_at_response = function(self, player)
    return table.find(player:getTableMark("th_shifu"), function(chen)
      return chen and not chen.dead
    end)
  end,
})
shifu_vs:addEffect(fk.PreCardUse, {
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("_th_shifu_failed-phase") > 0 and data.card and (data.card.trueName == "slash" or data.card.trueName == "jink")
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "_th_shifu_failed-phase", 0)
  end
})

Fk:loadTranslationTable{
  ["th_shifu&"] = "式符",
  [":th_shifu&"] = "你需要使用或打出【杀】或【闪】时，橙可以打出一张基本牌并摸一张牌，视为你使用或打出需要的牌。",

  ["#th_shifu-ask"] = "式符：你可以打出一张基本牌并摸一张牌，视为 %dest 使用了 %arg",
}

return shifu_vs